/*
 * StaticSingleton.h
 *
 *  Created on: 2014. 6. 19.
 *      Author: jjaehuny
 */

#ifndef STATICSINGLETON_H_
#define STATICSINGLETON_H_

namespace Framework { namespace Util {

#ifdef __LP64__
	typedef long long SINGLE_OFFSET;
#else
    typedef int SINGLE_OFFSET;
#endif


template<typename Type>
class StaticSingleton
{
public:
	StaticSingleton()
	{
		SINGLE_OFFSET offset = (SINGLE_OFFSET)((Type*)0 + 1) - (SINGLE_OFFSET)(StaticSingleton <Type>*)((Type*)0+1);
		m_Type = (Type*)((SINGLE_OFFSET)this + offset);
	}
	~StaticSingleton()
	{
		m_Type = 0;
	}

	static Type & Instance()
	{
		return ( *m_Type);
	}
	static Type * InstancePtr()
	{
		return (m_Type);
	}

private:

	static Type * m_Type;
};

template<typename Type> Type* StaticSingleton<Type>::m_Type = 0;


} /*Util*/ } /*Framework*/

#endif /* STATICSINGLETON_H_ */
